import { GoodsCategoryService } from "@/service";
import { GoodsCategoryTypes, ResponseVo } from "@/type";
import { reactive,computed,onBeforeMount, Ref } from "vue";

const useGoods = ():{
    goodsCategoryListOptions:Ref<{label:string,value:any}[]>
}=>{
    const state = reactive<{
        goodsCategoryList: GoodsCategoryTypes.GoodsCategoryItem[]
    }>({
        goodsCategoryList: []
    })

    onBeforeMount(()=>{
        getGoodsCategoryList();
    })

    const goodsCategoryListOptions = computed(()=>{
        return state.goodsCategoryList.map((category)=>{
            return {
                label:category.goodsCategoryName,
                value:category.goodsCategoryId
            }
        })
    })

    const getGoodsCategoryList = async()=>{
        let res:ResponseVo<GoodsCategoryTypes.GoodsCategoryItem[]> = await GoodsCategoryService.findAllGoodsCategory();
        if(res.code===0){
         state.goodsCategoryList = res.data;
        }    
    }

    return {
        goodsCategoryListOptions
    }
}

export default useGoods;